package com.minelx.datamicroscope.querylanguage.data.sql;

import com.minelx.datamicroscope.querylanguage.data.CollectingKey;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toList;

public class SelectList {

	private final Map<String, CollectingKey> aliasedTables;

	private final List<TableAliasedSelectItem> tableAliasedSelectItems;

	public SelectList(Map<String, CollectingKey> aliasedTables, List<TableAliasedSelectItem> tableAliasedSelectItems) {
		this.aliasedTables = aliasedTables;
		this.tableAliasedSelectItems = tableAliasedSelectItems;
	}

	public List<TableAliasedSelectItem> getSelectItemsBelongsTo(CollectingKey collectingKey) {
		return tableAliasedSelectItems.stream()
				.filter(selectItem -> aliasedTables.get(selectItem.getTableAlias()).equals(collectingKey))
				.collect(toList());
	}
}
